const types = require('@babel/types')
const template = require('@babel/template').default
const mytemplate = require('./index.js')

//将ast属性数组组合为ast对象
function arrayToObject(pathAry) {
    console.log('arrayToObject', pathAry.length);
    return types.objectExpression(pathAry);
}

const  TemplateBuilder = function(ast,vistors){
    const buildRequire = template(mytemplate.pageTemplate);
    ast = buildRequire({
        // LIFECYCLE: arrayToObject(vistors.lifeCycle.getData()),
        DATA: arrayToObject(vistors.data.getData()),
        METHODS: arrayToObject(vistors.methods.getData()),
        // COMPUTED: arrayToObject(vistors.computed.getData()),
        // WATCH: arrayToObject(vistors.watch.getData()),
    });
    return ast
}

module.exports = TemplateBuilder;